package com.qianli.cashmama.trade.common.utils;

import com.fqgj.common.utils.DateUtil;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Locale;

public class DateUtils {

    /**
     * 29 Aug 2019
     */
    public static String getEnglishDate(Date date) {
        SimpleDateFormat dateFormat = new SimpleDateFormat("dd MMM yyyy", Locale.ENGLISH);
        return dateFormat.format(date);
    }

    /**
     * 1981-07-05 -> 05 Jul 1981
     */
    public static String ch2EnDate(String chDate) {
        Date date = DateUtil.getDate(chDate, "yyyy-MM-dd");
        return getEnglishDate(date);
    }

    public static String formatEnglishDate(Date date) {
        String format = new SimpleDateFormat("MMM d", Locale.ENGLISH).format(date);
        String dateEnd = new SimpleDateFormat("d", Locale.ENGLISH).format(date);
        if (dateEnd.equals("1")) {
            dateEnd = "st";
        } else if (dateEnd.equals("2")) {
            dateEnd = "nd";
        } else if (dateEnd.equals("3")) {
            dateEnd = "rd";
        } else {
            dateEnd = "th";
        }
        format = format + dateEnd;
        return format;
    }
}
